<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/left.css">
    <link rel="stylesheet" href="css/jquery.dialogbox.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/vue.js"></script>
    <script src="js/jquery.dialogBox.js"></script>
    <title>学员信息管理</title>
    <script>
        $(function () {
            var vue = new Vue({
                el:'#app',
                data:{
                    pages:1,
                    <!-- 调整分页数据,查询参数设置-->
                    param:{stuId:0,stuName:0,page:1,rows:8},
                    url:'http://localhost:8889',
                    students:[],

                },
                methods:{
                    query:function () {
                        var that = this;
                        var ps = {
                            page:that.param.page,
                            rows:that.param.rows
                        }

                        if(that.param.stuId>0){
                            ps.stuId = that.param.stuId;
                            console.log('********')
                            console.log(ps.stuId)
                            console.log('********')
                        }
                        $.getJSON(that.url+'/student/query',ps,function(data){
                            that.students = data.list;
                            that.pages =  data.pages;
                            console.log(that.students)
                            console.log(that.subId)

                        })
                    },

                    <!--重置函数-->
                    reset:function () {
                        this.param.stuId = 0;
                        this.param.stuName = 0;
                        this.query();
                    },

                    <!--分页函数-->
                    setpage:function(page){
                        this.param.page = page;
                        this.query();
                    },
                    remove:function(stuId){
                        var that = this;
                        $('#type-delBox').dialogBox({
                            hasClose: true,
                            hasBtn: true,
                            width: 300,
                            height: 200,
                            confirmValue: '确认',
                            confirm: function(){
                                $.get(that.url+'/student/remove/'+stuId,function (data) {
                                    if(data!=null){
                                        that.query();
                                        setTimeout(function(){
                                            $('#type-delBox2').dialogBox({
                                                autoHide: true,
                                                time: 2000,
                                                width:300,
                                                height:60,
                                                content: '删除学员成功！'
                                            });
                                        }, 500);
                                    }else{
                                        $('#type-delBox2').dialogBox({
                                            autoHide: true,
                                            time: 2000,
                                            width:300,
                                            height:60,
                                            content: '删除学员失败！'
                                        });
                                    }
                                })
                            },
                            cancelValue: '取消',
                            title: '提醒',
                            content: '你确定删除该学员信息吗！'
                        });
                        /*$.get(that.url+'/student/remove/'+stuId,function (data) {
                            if(data!=null){
                                alert("删除成功"+stuId)
                                that.query();
                            }else{
                                alert("删除失败"+stuId)
                            }
                        })*/
                    },
                    show:function(stuId){
                        $('#type-delBox').dialogBox({
                            hasClose: true,
                            hasBtn: true,
                            width: 300,
                            height: 200,
                            confirmValue: '确认',
                            confirm: function(){
                                location.href = "student.html?stuId="+stuId;
                            },
                            cancelValue: '取消',
                            title: '提醒',
                            content: '你确定要修改学员信息吗！'
                        });

                    }
                }
            })
            $("#header").load("header.html");
            $("#left").load("left.html");
            vue.query();

        })
    </script>
    <style type="text/css" media="screen">
        .bg {
            background:url(images/subject/bg2.jpg) no-repeat center fixed;
            background-size:100%;
        }
        .bgcon{

            background: white;
            opacity:0.9;
        }
        .thead{
            border-bottom: #00FF00;
        }
        .tithead{
            margin-left:5px;
            margin-bottom: 30px;
        }
        .remark{
            margin-bottom: 20px;
            margin-right: 10px;
            color: #737373;
        }


    </style>
</head>
<body>
<div class="container-fluid bgcon" id="app">
    <div class="row" id="header">

    </div>
    <div class="row">
        <div class="col-md-2" id="left">

        </div>
        <div class="col-md-9" tyle="margin-left:30px;margin-top:10px">
            <div class="row tithead"><h3 class="glyphicon glyphicon-user"> 学员信息管理
            </h3></div>
            <div class="row" style="margin-top: 15px">

                <div class="col-md-2">
                    <select v-model="param.stuId" class="form-control">
                        <option value="0">请选择学员名称</option>
                        <option v-for="s in students" :value="s.stuId">{{s.stuName}}</option>
                    </select>
                </div>

                <div class="col-md-3">
                    <button @click="reset" class="btn btn-default" style="margin-right:10px">
                        <i class="glyphicon glyphicon-repeat"></i> 重置
                    </button>
                    <button @click="query" class="btn btn-primary">
                        <i class="glyphicon glyphicon-search"></i> 查询
                    </button>
                </div>
            </div>
            <div class="row" style="margin-top: 15px">
                <div class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover table-striped">
                            <thead class="thead">
                            <tr>
                                <th width="8%" class="text-center">序号</th>
                                <th width="8%" class="text-center">学员账号</th>
                                <th width="10%" class="text-center">学员名称</th>
                                <th width="15%" class="text-center">电话</th>
                                <th width="7%" class="text-center">性别</th>
                                <th width="7%" class="text-center">年龄</th>
                                <th width="10%" class="text-center">微信号</th>
                                <th width="10%" class="text-center">备注</th>
                                <th class="text-center" colspan="3">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr v-for="(s,index) in students" class="text-center">
                                <td>{{index+1}}</td>
                                <td>{{s.number}}</td>
                                <td>{{s.stuName}}</td>
                                <td>{{s.phone}}</td>
                                <td v-if="s.stuSex === 1">男</td>
                                <td v-else-if="s.stuSex === 0">女</td>
                                <td>{{s.stuAge}}</td>
                                <td>{{s.email}}</td>
                                <td>{{s.remark}}</td>

                                <td>
                                    <button @click="show(s.stuId)" class="btn btn-sm btn-warning">修改</button>
                                </td>
                                <td>
                                    <button @click="remove(s.stuId)" class="btn btn-sm btn-danger">删除</button>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <!--分页处理-->
            <div class="row">
                <div class="col-md-12 text-center">
                    <nav aria-label="Page navigation">
                        <ul class="pagination" style="margin: 0">
                            <li @click="setpage(1)">
                                <a href="#" aria-label="Previous">
                                    <span aria-hidden="true">&laquo;</span>
                                </a>
                            </li>
                            <li v-for="p in pages" @click="setpage(p)">
                                <a href="#">{{p}}</a>
                            </li>
                            <li @click="setpage(pages)">
                                <a href="#" aria-label="Next">
                                    <span aria-hidden="true">&raquo;</span>
                                </a>
                            </li>
                        </ul>
                    </nav>
                </div>
            </div>
            <div class="row text-right remark"><h5>备注：学员详细信息展示. </h5></div>
        </div>
    </div>
</div>
<div id="type-delBox"></div>
<div id="type-delBox2"></div>
</body>
</html>